
<div class="wrapMain">
	<div id="row">


		    <div class="col-md-8"> 
        <ul class="breadcrumb" style="background-color:#fff">
        	<li><a href="<?php echo HOME ?>"><i class="fa fa-home"></i></a></li>
            <li><a href="<?php echo HOME ?>truyen">Truyện</a></li>
             <li><?php echo $data['theloai2']['2']; ?></li>
             
        </ul>
    
        <!-- START TRUYEN DE CU -->
        <div class="panel panel-default">

  		<div class="panel-body">
  			
            <div class="row" itemscope itemtype="http://schema.org/Book">
             
            		<div class="col-md-3 col-sm-3 col-xs-12">
                    	<div class="item_truyen_box" style="text-align:center">
                        		   <?php if($_SESSION['mobile']!=0){?> <h1 class="name" itemprop='name'><span style="line-height:30px"><?php echo $data['ten'] ?></span></h1><?php }?>
                                <div class="img">
                                	<img itemprop='image' src="<?php echo TRUYEN_IMAGE_LOCAL.$data['hinhanh'] ?>" class="img-rounded" />
                                </div>
                                <?php if($_SESSION['mobile']==0){ ?>
                               	<div class="like">
                                	<div>
                                	Hãy Like nếu thấy truyện hay 
                                    </div>
                                    
                                   <div class="fb-like" data-href="<?php echo url();?>" data-width="150" data-layout="box_count" data-action="like" data-show-faces="true" data-share="true"></div>
                                </div>
                                <?php }?>
                                  <div class="btn-group-vertical" >
         <?php
			if($data['chuong_list']){?>
        <a class="btn btn-info btn-sm" role="button" href="<?php echo $data['chuongmoinhat_url']?>">Đọc Chương Mới Nhất <i class="fa fa-long-arrow-right"></i> </a>
        <a class="btn btn-info btn-sm" role="button" href="<?php echo $data['chuongbatdau_url']?>">Đọc Từ Đầu <i class="fa fa-thumbs-up"></i> </a>
        	<?php } ?>
        <a class="btn btn-info btn-sm follow-story" role="button">Theo Dõi Truyện  Này <i class="fa fa-bookmark"></i> </a>	
       
        
        </div>
                              	
                        </div><!-- End item_truyen_box -->
                    </div> <!-- End of col-md-3 -->
                      
                    <div class="col-md-9 col-sm-9 col-xs-12">
                    <div class="item_truyen_detail">
                    <?php if($_SESSION['mobile']==0){?> <h1 class="name" itemprop='name'><?php echo $data['ten'] ?></h1><?php }?>

                    	<table class="table" id="truyen_detail_metadata">

                    		<tr>
                    			<td class="author" align="right" width="120">Tác giả:</td>
                    			<td class="author"><span><a href="<?php echo url_truyen_tacgia($data['tacgia']) ?>" ><span itemprop="author"><?php echo $data['tacgia']?></span></a></span></td>
                    		</tr>
                    		<tr>
                    			<td class="theloai" align="right">Thể Loại:</td>
                    			<td class="theloai"><?php echo $data['theloai2']['1']; ?></td>
                    		</tr>
                    		<tr>
                    			<td class="tinhtrang" align="right">Tình Trạng:</td>
                    			<td class="tinhtrang"><span><?php echo $data['tinhtrang-text']; ?></span></td>
                    		</tr>
                    		<tr>
                    			<td class="view" align="right">Lượt Xem:</td>
                    			<td class="view"><span class="badge"><?php echo $data['views']; ?></span></td>
                    		</tr>
                    		<tr>
                    			<td class="tukhoa" align="right"> Từ Khóa:</td>
                    			<td class="tukhoa"><?php  echo $data['tag']?></td>
                    		</tr>
                    		<tr>
                    			<td class="stat_info" align="right">Truyện đăng bởi:</td>
                    			<td class="stat_info"><span class="author"><?php echo $data['user_upload']; ?></span>  &nbsp;&nbsp;&nbsp;<span class="time"><?php echo time_ago($data['time_upload']); ?></span></td>
                    		</tr>
                    		<tr>
                    			<td class="stat_info2" align="right">Chương Mới Nhất :</td>
                    			<td class="stat_info2">
                    				<span>
                    					<a href="<?php echo $data['chuongmoinhat_url'] ?>"><?php echo $data['chuongmoinhat']; ?></a>
                    				</span>
                    				</td>
                    		</tr>
                    	</table>
                    	
                        <div class="noidung" itemprop='description'>
                         <?php 
                        /* if($data['noidung']==''){ 
                         	mb_strlen($data['gioithieu']) > 200 ? $content_show = mb_substr($data['gioithieu'], 0, 200) . '...<p class="viewmore">Xem thêm</p>'  : $data['gioithieu'];
                         }else{
							mb_strlen($data['noidung']) > 200 ? mb_substr($data['noidung'], 0, 200) . '...<p class="viewmore">Xem thêm</p>' : $data['noidung'];
						 }  */

						if($data['noidung']==''){
							$content_show = $data['gioithieu'];
							
						}else{
							$content_show = $data['noidung'];
						}
						echo $content_show;
						
						?>
                         
                         </div>
                               
                        </div><!-- End item_truyen_box -->
                    </div> <!-- End of col-md-9 -->
                   
                    <div  class="clearfix"></div>
                     <?php if($_SESSION['mobile']==0){?> 
                    <div class="fanpage">
                    		<div class="title">Hãy ủng hộ Mộng bằng cách like fan page nhé, mỗi lần click like là bạn đã ủng hộ và động viên chúng tôi rất nhiều rồi đó</div>
                   			 <div class="fb-like" data-href="https://www.facebook.com/24hmanga" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>	
                    </div>
                
                    	<?php }?>

            
            
            
                <!-- Start footable -->
           
               
                 <link rel="stylesheet" type="text/css" href="public/exts/footable/css/footable.core.min.css"/>
             	<script type="text/javascript" src="public/exts/paging/js/jquery.jqpagination.min.js"></script>
                <?php $page=ceil($data['sochuong']/30);?>	
				
  			<?php
			if(isset($_SESSION['user'])){
			$db=new db;
			$db->connect();
			$db->query(' select * from truyen_history where truyen_id='.intval($_GET['id']).' and username="'.$_SESSION['user']['username'].'"');
					if($db->num_rows()>0){
						$his=$db->fetchOne();
					 ?>
							<div class="alert alert-warning">
						   <strong>Chương Theo Dõi </strong>  <span class="pull-right"> <a href="<?php echo $his['url']; ?>"><?php echo $his['ten']; ?> </a>-<span style="font-size:11px"><?php echo time_ago($his['ngay']); ?></span></span>
							</div>
					<?php
					}
			}?>
        <Br/>
                <div id="wrap_chuong_table">
              	<div id="chuong_table">
                 <table id="table_data" class="footable table  table-striped">
	<thead>
		<tr>
			<th>Chương</th>
			<th data-hide="phone">Người Đăng</th>
			
</tr>
	</thead>

	<tbody>
    	<?php
			if($data['chuong_list']){

					foreach($data['chuong_list'] as $row){
				 ?>
						  <tr>
					<td><a href="<?php echo url_truyen_chuong($row['id'],$row['alias'],$data['alias']) ?>"> <?php echo $row['ten'] ?></a></td>
						<td> <?php echo $row['user_upload'] ?></td>
				
				  </tr>
						 <?php }
			}else{?>
            		<tr>
					<td colspan="4"><h1 class="text-center">Chúng tôi đang cập nhật</h1></td>
					
				
				  </tr>
          	<?php }?>
          </tbody>
        
          </table>
          </div> <!-- End table chuong -->
          </div><!-- end wrap_chuong_table -->
            <?php
			if($data['chuong_list']){?>
                 <div style="width:300px; margin:auto">
                 <div class="pagination">
                <a href="#" class="first" data-action="first">&laquo;</a>
                <a href="#" class="previous" data-action="previous">&lsaquo;</a>
                <input type="text" readonly="readonly" data-max-page="<?php echo $page ?>" />
                <a href="#" class="next" data-action="next">&rsaquo;</a>
                <a href="#" class="last" data-action="last">&raquo;</a>
				</div>
             	 </div>
            <?php }?>  
                
            </div> <!-- End of row -->
  <script>
                $('.pagination').jqPagination({
					paged: function(page) {
						$('#wrap_chuong_table').append('<div class="loading" id="mainLoading"><div id="loadMoreItems" class="normalLoadBtn"><img width="20" src="public/images/loading.gif" alt="loading" /> Loading </div><div class="clr"></div></div>');
						$('#wrap_chuong_table').css('opacity', 0.4);
						$('#mainLoading').css('display', 'block').center();
						//Remove dom hien tai de nhe hơn
					$('#table_data').remove();
						// Make ajax request with page --
						
			$.ajax({
	    		url : "index.php",
	    		type : 'POST',
	    	//exit();
	    		data : {
		    		module: 'truyen', 
	    			act :'pagination', 
	    			page : page,
					truyen: <?php echo intval($_GET['id']) ?>
				
	    		},
	    		
	    		success : function(data){
					
					$('#chuong_table').html(data);
	    			$('#mainLoading').remove();
	    			$('#wrap_chuong_table').css('opacity', 1);
	    	
	    		}
	    	});


						//End of make ajax request 
					}
					});
                </script>
    
                        
  
  		</div> <!-- End of panel body -->
		</div> <!-- End of panel -->

        <!-- End truyen de cu -->
        <div class="panel panel-default">
 		 <div class="panel-heading">
         		<ul class="mn_nav">
                 <li><span class="head">Thảo Luận</span></li>
            
             
              
            </ul>
            <div class="clearfix"></div>
         </div>
  		<div class="panel-body">
        
                                 <script>
			window.fbAsyncInit = function() {
 FB.init({appId: '<?php echo FB_ID;?>', status: true, cookie: true, xfbml: true});

     FB.Event.subscribe('comment.create', function(response) {
          var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
      var user = FB.Data.query(
       "select name, id, url, pic_square from profile where id in"
     + "(select fromid from {0})", commentQuery);
 
  FB.Data.waitOn([commentQuery,user], function () {
   ct = commentQuery.value[0].text;
   u = user.value[0].name;
   td='<?php echo2($data['post']['title']) ?>';
   url='<?php echo url() ?>';
   m='truyen';
   ip='<?php echo get_ip(); ?>';
   id='<?php echo $_GET['id'] ?>';
	// Query get user info with fromid
	//Send data to server using ajax ------ KAKAKAKAKAKA
			 var   values='comment_user='+u+'&comment_tieude='+td+'&comment_url='+url+'&comment_type='+m+'&ip='+ip+'&comment_id='+id+
    '&comment_content='+ct+'&module=user&act=ajax&add_comment';
	
  	$.ajax({
      url: "index.php",
      type: "post",
      data: values,
      success: function(data){
          },
   
    }); 
	
    // Use your preferred way to inform the server to save comment
     });
 });         
 };
 
 </script>  
  			<!-- Truyen moi content -->
<div class="fb-comments" data-href="<?php echo url();?>" data-numposts="5" data-colorscheme="light"></div>
            <!-- End truyen moi content -->	
         
  
  		</div> <!-- End of panel body -->
		</div> <!-- End of panel -->

      
        
        


</div> <!-- COL MD 9 -->
  
                    <div class="col-md-4">
                     <?php  render_fanpage(); ?>
  						<?php truyen_render_theloai(); ?>
     	<!-- START Render TRUYEN View -->	<?php truyen_render_view(); ?>	
 <!-- START RENDER video comment --> <?php render_pick(); ?> <!-- End RENDER video comment --> 
 <!-- START RENDER video Xem Nhieu -->     <?php blog_render_view(); ?>   <!-- end video xem nhieu -->


		



					</div> <!-- End col-md-3 right -->




	
	</div><!-- end row -->
</div><!-- end wrapMain -->
<div class="clearfix"></div>

<script type="text/javascript">
	$(document).ready(function(){
		$('.follow-story').live('click',function(e){
			e.preventDefault();
			username = '<?= $_SESSION['user']['username']; ?>';
			if(!username){
				window.location.href = '<?= LOGIN ?>';
				return;
			}
			truyen_id = '<?= $data['id']; ?>';
			username = '<?= $_SESSION['user']['username']; ?>';
			
			$.ajax({
				url: 'index.php?module=user&act=ajax&follow_story=1',
				type: 'POST',
				data: {truyen_id: truyen_id, username: username},
				success: function(data){
					if(data) newData = $.parseJSON(data);
					if(newData.error){
						popupMessage('Lỗi', [newData.error], 'alert-danger');
					}else if(newData.message){
						popupMessage('Thành công', [newData.message], 'alert-success');
					}
				},
			});
		});

		if($('.noidung').height() > 150){
			$('.noidung').css('height', '140').css('overflow', 'hidden');
			$('.item_truyen_detail').append('<p id="threedots" style="text-align:center; font-size: 15px;">...</p><p class="viewmore extend">Xem thêm</p>');
			
		}

		$('.item_truyen_detail .viewmore').live('click', function(e){
			if($(this).hasClass('shorten')){
				$('.noidung').css('height', '140').css('overflow', 'hidden');
				$(this).addClass('extend');
				$(this).html('Xem thêm');
				$(this).removeClass('shorten');
				$('#threedots').html('...');
				
			}else{
				$('.noidung').css('height', 'auto');
				$(this).addClass('shorten');
				$(this).html('Rút gọn');
				$(this).removeClass('extend');
				$('#threedots').html('');
			}
		});

		$('.pagination a').live('click', function(e){
			
			$('#wrap_chuong_table').append('<div class="loading" id="mainLoading"><div id="loadMoreItems" class="normalLoadBtn"><img width="20" src="public/images/loading.gif" alt="loading" /> Loading </div><div class="clr"></div></div>');
			window.scroll(0,findPos(document.getElementById("chuong_table")) - 50);
		});
	});
</script>